<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>{$basic.title}</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link href="__LAYUI__/css/layui.css" rel="stylesheet">
    <link href="__LAYUI__/css/ah.css" rel="stylesheet">
</head>
<body>
<div class="wrapper-content">
<div class="ibox">
	<div class="ibox-title"><h3>编辑</h3>
	</div>
	<div class="ibox-content">
		<form class="layui-form" enctype="multipart/form-data" lay-filter="amData" id="amData" action="{:url('links/edit')}">
				  <div class="layui-form-item">
					<label class="layui-form-label">名称</label>
					<div class="layui-input-block">
					  <input type="text" name="name" autocomplete="off" placeholder="请输入名称" class="layui-input">
					</div>
				  </div>
				  <div class="layui-form-item">
					<label class="layui-form-label">状态</label>
					<div class="layui-input-inline">
					  <input type="checkbox" name="status"  lay-skin="switch" lay-filter="switch" lay-text="ON|OFF">
					</div>
				  </div>
				  <div class="layui-form-item">
					<div class="layui-inline">
					  <label class="layui-form-label">位置</label>
					  <div class="layui-input-inline">
						<select name="site">
							{volist name="Think.config.links_site" id="vo"}
								<option value="{$key}">{$vo}</option>
							{/volist}
						</select>
					  </div>
					</div>
				  </div>
				  <div class="layui-form-item">
					<label class="layui-form-label">URL</label>
					<div class="layui-input-block">
					  <input type="text" name="url" autocomplete="off" placeholder="请输入URL" class="layui-input">
					</div>
				  </div>
					<div class="layui-form-item">
							<label class="layui-form-label">图标</label>
							<div class="layui-input-inline">
							  <input type="text" id="icoValue" name="icon"  class="layui-input">
							</div>
					</div>
					<div class="layui-form-item">
							<label class="layui-form-label">扩展</label>
							<div class="layui-input-block">
							<textarea placeholder="备用内容/广告" class="layui-textarea" name="ext"></textarea>
							</div>
					</div>
							<input type="text" name="type" value="1" class="layui-hide">
							<input type="text" name="id" class="layui-hide">
							<button type="button" class="layui-btn" lay-submit lay-filter="saveData">保存提交</button>
		</form>
	</div>
</div>
</div>
</body>
<script src="__LAYUI__/layui.js"></script>
<script>
var d_json = {$d_json|raw};
function getValue(v) {
		document.getElementById("icoValue").value=v; 
	}
  layui.use(['layer','form',], function(){
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
	var xaoam ={
		  close:function(msg){
			  layer.msg(msg);
			  if(parent.length > 0){
				let index = parent.layer.getFrameIndex(window.name);
				  parent.layer.close(index);
				  console.log(parent.Wxaoam);
				  parent.Wxaoam.init();
			  }
			  
		  },
		  tool:function(){
				$('#icoValue').click(function(){
					layer.open({
					  type: 2,
					  title: ' ',
					  area: ['380px', '260px'],
					  content: ['__UI__/ico.html', 'no'],
		  
					});
				});
			  $('#del_node').on('click',function(ele){
						$.ajax({
							url:$(this).data('url'),
							data:{'id':$('[name="id"]').val()},
							dataType:'json',
							type:'POST',
							success:function(res){
								if(res.code == 200){
									xaoam.close(res.msg);
								}else{
									layer.msg(res.msg);
								}
							}
						})
			  });
				form.on('submit(saveData)', function(data){
					var action = $(this).parent('form').attr('action');
					var Fdata = new FormData(document.getElementById("amData"));
					$.ajax({
						url:action,
						data:Fdata,
						dataType:'json',
						type:'POST',
						contentType: false,
						processData: false,
						success:function(res){
							if(res.code == 200){
								xaoam.close(res.msg);
							}else{
								layer.msg(res.msg);
							}
						}
					})
				  return false; 
				});
		  },
		init:function(){
			form.val('amData',d_json);
		}
	};
	xaoam.tool();
	xaoam.init();

  });
</script>
</html>
